home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
usenet
/
sources
/
volume90
/
util
/
kickdate
/
part01
/
settime.c
< prev
Wrap
C/C++ Source or Header
|
1990-10-10
|
2KB
|
95 lines
/* KICKDATE - Copyright 1990 Joe Porkka
FREELY DISTRIBUTABLE
Purpose: Keeps the current date on the Kickstart disk
for A1000 owners with autoboot harddrives.
Version 1.0
*/
#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/memory.h>
#include <exec/interrupts.h>
#include <exec/ports.h>
#include <exec/libraries.h>
#include <exec/tasks.h>
#include <exec/io.h>
#include <exec/devices.h>
#include <devices/timer.h>
#include "settime.h"
APTR TimerBase;
long
SetNewTime(secs)
long secs;
{
struct timerequest *tr;
tr= CreateTimer(UNIT_MICROHZ);
if(tr==0) return -1;
tr->tr_node.io_Command = TR_SETSYSTIME;
tr->tr_time.tv_secs=secs;
tr->tr_time.tv_micro=0;
DoIO(tr);
DeleteTimer(tr);
return 0;
}
long
GetSysTime(void)
{
struct timeval tv;
struct timerequest *tr;
tr= CreateTimer(UNIT_MICROHZ);
if(tr==0) return -1;
tr->tr_node.io_Command = TR_GETSYSTIME;
DoIO(tr);
tv =tr->tr_time;
DeleteTimer(tr);
return tv.tv_secs;
}
void
DeleteTimer(tr)
struct timerequest *tr;
{
struct MsgPort *tp;
if(tr!=0) {
tp = tr->tr_node.io_Message.mn_ReplyPort;
if(tp!=0) DeletePort(tp);
CloseDevice(tr);
DeleteExtIO(tr, sizeof(struct timerequest));
}
}
struct timerequest *
CreateTimer(unit)
ULONG unit;
{
int error;
struct MsgPort *timerport;
struct timerequest *timermsg;
timerport = (struct MsgPort *)CreatePort(0,0);
if(timerport == 0) {
return 0;
}
timermsg = (struct timerequest *) CreateExtIO(timerport, sizeof(struct timerequest));
if(timermsg == 0) {
DeletePort(timerport);
return 0;
}
error = OpenDevice(TIMERNAME, unit, timermsg, 0);
if(error !=0) {
DeleteTimer(timermsg);
return 0;
}
return timermsg;
}